package com.tencent.wxcloudrun;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.StringUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@EnableScheduling
@Slf4j
@MapperScan("com.tencent.wxcloudrun.mapper")
public class WxCloudRunApplication extends SpringBootServletInitializer {

  public static void main(String[] args) throws UnknownHostException {
    ConfigurableApplicationContext run = SpringApplication.run(WxCloudRunApplication.class, args);
    Environment env = run.getEnvironment();
    String ip = InetAddress.getLocalHost().getHostAddress();
    String port = env.getProperty("server.port");
    String path = env.getProperty("server.servlet.context-path");
    if (StringUtils.isEmpty(path)) {
      path = "";
    }
    log.info("\n----------------------------------------------------------\n\t" +
            "Application  is running! Access URLs:\n\t" +
            "Local访问网址: \t\thttp://localhost:" + port + path +"/doc.html" + "\n\t" +
            "External访问网址: \thttp://" + ip + ":" + port + path  + "\n\t" +
            "API文档访问网址: \thttp://" + ip + ":" + port + path +"/doc.html" + "\n\t" +
            "----------------------------------------------------------");
  }
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    // 注意这里要指向原先用main方法执行的Application启动类
    return builder.sources(WxCloudRunApplication.class);

  }
}
